import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)

  function increment() {
    count.value++
  }

  return { count, increment }
})

// 视频数据存储
export const useVideoStore = defineStore('video', () => {
  // 当前视频数据
  const currentVideo = ref<any>(null)

  // 视频详情页相关数据
  const videoDetail = ref<any>(null)
  const relatedList = ref<any[]>([])
  const commentList = ref<any[]>([])
  const nextPageUrl = ref<string | null>(null)
  const loading = ref(false)

  // 设置当前视频
  const setCurrentVideo = (video: any) => {
    currentVideo.value = video
  }

  // 设置视频详情
  const setVideoDetail = (detail: any) => {
    videoDetail.value = detail
  }

  // 设置相关推荐列表
  const setRelatedList = (list: any[]) => {
    relatedList.value = list
  }

  // 设置评论列表
  const setCommentList = (list: any[]) => {
    commentList.value = list
  }

  // 追加评论列表
  const appendCommentList = (list: any[]) => {
    commentList.value.push(...list)
  }

  // 设置下一页URL
  const setNextPageUrl = (url: string | null) => {
    nextPageUrl.value = url
  }

  // 清空视频详情页数据
  const clearVideoDetail = () => {
    videoDetail.value = null
    relatedList.value = []
    commentList.value = []
    nextPageUrl.value = null
  }

  return {
    currentVideo,
    setCurrentVideo,
    // 视频详情页数据
    videoDetail,
    relatedList,
    commentList,
    nextPageUrl,
    loading,
    setVideoDetail,
    setRelatedList,
    setCommentList,
    appendCommentList,
    setNextPageUrl,
    clearVideoDetail
  }
})
